<?php

namespace Acme\CommonBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;

class TestController extends Controller
{	
    /**
     * @Route("/test", name="AcmeCommonBundle_Test")
     * @Template()
     */
    public function indexAction() {
    	// @ORM\JoinColumn(name="contest_type", referencedColumnName="id")
    	// shouldn't use the property name but column name
    	
    	/*$condition['id'] = 1;
    	$em = $this->getDoctrine()->getEntityManager();
    	$user = $em->getRepository('AcmeContestBundle:CtInfo')->findCtByConditionJoined($condition);
    	echo "<pre>";
    	print_r($user->getApplyByInfo()->getUserInfo()->getUniversityInfo()->getName());*/
    	/*$propertyToSetModifiedBy = array(
    			'name', 'contestType', 'isVisiable', 'applyReason',
    			'enrollStart', 'enrollEnd', 'contestStart', 'contestEnd',
    			'reviewType', 'reviewStart', 'reviewEnd', 'instruction', 'flag');
    	
    	echo "<pre>";
    	print_r($propertyToSetModifiedBy);
    	if ($propertyToSetModifiedBy == array_diff($propertyToSetModifiedBy, array())) {
    		echo 'true';
    	}
    	//print_r(array_diff($propertyToSetModifiedBy, array('flag', 'applyTime')));
    	//echo count(array_diff($propertyToSetModifiedBy, array('flag', 'applyTime')));
    	return ;*/
    	
    	$_security_secured_area = unserialize($this->get('session')->get('_security_secured_area'));
    	
    	foreach ($_security_secured_area->getRoles() as $v) {
    		echo "<pre>";
    		print_r($v->getRole());
    	}
    	
    	/*$securityContext = $this->get('security.context');
    	$user = $securityContext->getToken()->getUser();
    	$securityIdentity = UserSecurityIdentity::fromAccount($user);
    	echo "<pre>";
    	print_r($securityIdentity);
    	return ;*/
    }
}
